angular.module('app').controller('detailPostCtrl', 
['$scope', '$rootScope', 'http', 'stateV',
function($scope, $rootScope,http, stateV) 
{	
	function ngInit(){
		$rootScope.htmlshow = false;
		$scope.post = stateV.get();
		$scope.post.details = JSON.stringify($scope.post.details)
		$scope.post.imgs = JSON.stringify($scope.post.imgs)
		$scope.post.size = JSON.stringify($scope.post.size)
		// $scope.post.imgs = $scope.post.imgs.join(";");
	}
	

	// 修改商品
	$scope.updatePost = function(){
		if(''==$scope.post.details ||!angular.isObject(JSON.parse($scope.post.details))){
			alert("商品详细信息文本格式错误或不能为空")
			return false;
		}
		if(!angular.isObject(JSON.parse($scope.post.size))){
			alert("商品规格文本格式错误或不能为空")
			return false;
		}
		if(!angular.isObject(JSON.parse($scope.post.imgs))){
			alert("商品详细信息文本格式错误或不能为空")
			return false;
		}
		console.log($scope.post)
		var reqUrl = globalConfig.web + '/posts/update';
		http.post(reqUrl, $scope.post, function(data, status){
			if(status==200){
				alert('修改成功');
			}
		})
	}

	 ngInit();
}]);